package com.laiketui.order.mapstruct;

import com.laiketui.order.api.dto.OrderParentMessageDTO;
import com.laiketui.order.api.dto.pay.BalanceRecordDTO;
import com.laiketui.order.domain.BalanceRecord;
import com.laiketui.order.domain.OrderParentMessage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Mapper
public interface BalanceRecordMapstructMapper {
    BalanceRecordMapstructMapper INSTANCE = Mappers.getMapper(BalanceRecordMapstructMapper.class);


    @Mapping( target = "recordAmount",expression="java(com.laiketui.order.utils.PriceUtil.longToBigDecimalPrice(message.getRecordAmount()))")
    @Mapping( target = "recordContent",expression="java(com.laiketui.order.api.enums.BalanceRecordTypeEnum.getName(message.getRecordType()))")
    BalanceRecordDTO toDTO(BalanceRecord message);


    default List<BalanceRecordDTO> toDTOs(List<BalanceRecord> orderParents){
        if(CollectionUtils.isEmpty(orderParents)){
            return new ArrayList<>();
        }
        return orderParents.stream().map(this::toDTO).collect(Collectors.toList());
    };
}
